package com.wisemoresystem.seal.util.file;

import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;

import sun.misc.BASE64Decoder;

public class File64CodeTools {

	public static void writeFiles(File newFile, String pic) {
		// TODO 写 64Encode 编码的图片文件
		if (!newFile.getParentFile().exists()) {
			newFile.getParentFile().mkdirs();
		}
		OutputStream out = null;

		try {
			// Base64解码
			byte[] b = new BASE64Decoder().decodeBuffer(pic);
			for (int i = 0; i < b.length; ++i) {
				if (b[i] < 0) {// 调整异常数据
					b[i] += 256;
				}
			}
			out = new FileOutputStream(newFile);
			out.write(b);
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			FileTools.close(out);
		}
	}

}
